package com.chaos.auth.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.chaos.auth.api.data.oauth.OauthClientDetailsData;
import com.chaos.auth.entity.OauthClientDetails;
import com.chaos.auth.service.oauth.OauthClientDetailsService;
import com.chaos.framework.model.dto.ID;
import com.chaos.framework.model.dto.page.PageQueryDto;
import com.chaos.framework.model.dto.result.data.BooleanResult;
import com.chaos.framework.model.dto.result.data.DataResult;
import com.chaos.framework.model.dto.result.list.ListResult;
import com.chaos.framework.model.dto.result.page.PageResult;
import com.chaos.framework.starter.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Jacky
 * @since 2024-05-07
 */
@Slf4j
@RestController
@Api(tags = "管理模块")
@RequestMapping("/oauthClientDetails")
public class OauthClientDetailsController extends BaseController<OauthClientDetailsData> {
    @Autowired
    private OauthClientDetailsService oauthClientDetailsService;

    @PostMapping("/add.admin")
    @ApiOperation(value = "新增", httpMethod = "POST")
    public BooleanResult add(@RequestBody @Validated OauthClientDetailsData data) {
        oauthClientDetailsService.insertModel(data);
        return booleanResult(true);
    }

    @PostMapping("/list.admin")
    @ApiOperation(value = "列表", httpMethod = "POST")
    public ListResult<OauthClientDetailsData> list(@RequestBody OauthClientDetailsData data) {
        return listResult(oauthClientDetailsService.selectByData(data));
    }

    @PostMapping("/page.admin")
    @ApiOperation(value = "分页", httpMethod = "POST")
    public PageResult<OauthClientDetailsData> page(@RequestBody PageQueryDto<OauthClientDetailsData> data) {
        return pageResult(oauthClientDetailsService.selectByPage(data));
    }

    @PostMapping("/one.admin")
    @ApiOperation(value = "详情", httpMethod = "POST")
    public DataResult<OauthClientDetailsData> one(@RequestBody String clientId) {
        return dataResult(oauthClientDetailsService.selectByClientId(clientId));
    }

    @PostMapping("/update.admin")
    @ApiOperation(value = "编辑", httpMethod = "POST")
    public BooleanResult update(@RequestBody @Validated OauthClientDetailsData data) {
        return booleanResult(oauthClientDetailsService.updateModelByID(data));
    }

    @PostMapping("/saas/one.admin")
    @ApiOperation(value = "详情", httpMethod = "POST")
    public DataResult<OauthClientDetailsData> saasOne(@RequestBody OauthClientDetailsData data) {
        return dataResult(oauthClientDetailsService.selectSaasByData(data));
    }


}
